// ignore_for_file: sort_child_properties_last

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'package:lottie/lottie.dart';

import '../util.dart';

/// @Author : 王亚东

/// @Time : On 2022/3/2 14:02

class IflyDialog extends StatefulWidget {
  const IflyDialog({Key? key}) : super(key: key);

  @override
  _IflyDialogState createState() => _IflyDialogState();
}

class _IflyDialogState extends State<IflyDialog> {
  String text = '请说，正在聆听...';

  @override
  void initState() {
    super.initState();

    actionAudio();
  }

  @override
  void dispose() {
    super.dispose();
    // XFApiUtils().cancel();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: Get.width,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          Stack(
            alignment: Alignment.topRight,
            children: [
              Center(
                child: Container(
                  decoration: BoxDecoration(
                      color: Colors.grey,
                      borderRadius: BorderRadius.all(Radius.circular(30.r))),
                  width: 100.w,
                  height: 3.h,
                  margin: EdgeInsets.only(top: 10.r, bottom: 0),
                ),
              ),
              Positioned(
                child: IconButton(
                  onPressed: () {
                    // XFApiUtils().cancel();
                    Get.back();
                  },
                  iconSize: 30.r,
                  icon: Icon(
                    Icons.close,
                    color: ColorsUtil.red,
                    size: 25.r,
                  ),
                ),
              ),
            ],
          ),
          Expanded(
              child: Text(
            text,
            style: TextStyle(fontSize: 16.sp, height: 1.5),
            textAlign: TextAlign.start,
          )),
          Expanded(
            child: LottieBuilder.asset(
              'assets/jsons/voice_loading.json',
              animate: true,
              repeat: true,
              reverse: true,
              // width: 200.r,
              width: Get.width - 120.r,
              fit: BoxFit.fill,
            ),
          ),
          const Divider(
            height: 1,
            color: ColorsUtil.separator,
          ),
          GestureDetector(
              onTap: () {
                // XFApiUtils().stop().then((value) {
                //   Get.back(result: text);
                // });
              },
              child: Container(
                width: 100.r,
                height: 40.r,
                alignment: Alignment.center,
                margin: EdgeInsets.only(top: 15.r, bottom: 15.r),
                decoration: BoxDecoration(
                  color: ColorsUtil.red,
                  borderRadius: BorderRadius.circular(20.r),
                ),
                child: Text(
                  '说完了',
                  style: TextStyle(color: Colors.white, fontSize: 16.sp),
                ),
              ))
        ],
        mainAxisSize: MainAxisSize.min,
      ),
      height: 0.45.sh,
      padding: EdgeInsets.fromLTRB(15.r, 0, 15.r, SizeFit.safeBottom),
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.only(
              topRight: Radius.circular(30.r), topLeft: Radius.circular(30.r))),
    );
  }

  void actionAudio() async {
    // await XFApiUtils().start((String result) {
    //   print('---res---' + result.toString());

    //   setState(() {
    //     text = result;
    //   });
    // });
  }
}
